package org.example.spring.self.demo.s3;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件描述
 *
 * @author yezhou41127
 * @date: 2022年08月01日
 */
public class TestMethodTemplate {

	public static void main(String[] args) {
		MyBeanFactory beanFactory = new MyBeanFactory();
		beanFactory.addBeanPostProcessor(() -> {
			System.out.println("解析");
		});
		beanFactory.getBean();
	}

	// 模板方法
	static class MyBeanFactory {
		private List<BeanPostProcessor> processors = new ArrayList<>();

		public Object getBean() {
			Object bean = new Object();
			System.out.println("构造" + bean);
			System.out.println("依赖注入" + bean);

			for (BeanPostProcessor processor : processors) {
				processor.inject();
			}

			System.out.println("初始化" + bean);
			return bean;
		}

		public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
			this.processors.add(beanPostProcessor);
		}
	}

	static interface BeanPostProcessor {
		void inject();
	}
}
